현재 위치: > 함수 카테고리 모음> property_exists

property_exists

객체 나 클래스 에이 속성이 있는지 확인하십시오
이름:property_exists
분류:수업과 대상
사용 언어:php
한 줄 설명:객체 또는 클래스에 지정된 속성이 있는지 확인합니다.

함수 이름 : property_exists ()

함수 설명 : property_exists () 함수 객체 또는 클래스에 지정된 속성이 있는지 확인합니다.

매개 변수 :

  • $ 클래스 : 필수. 확인할 클래스 이름 또는 개체.
  • $ 속성 : 필수. 확인할 속성 이름.

반품 값 :

  • 부동산이 존재하고 접근 할 수있는 경우 True를 반환합니다.
  • 속성이 존재하지 않거나 액세스 할 수없는 경우 False가 반환됩니다.

해당 버전 : PHP 4, PHP 5, PHP 7

사용 예 :

  1. 클래스에 지정된 속성이 있는지 확인하십시오.
 class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'name')) { echo "The 'name' property exists."; } else { echo "The 'name' property does not exist."; } // 输出:The 'name' property exists.
  1. 객체에 지정된 속성이 있는지 확인하십시오.
 class MyClass { public $name = "John"; private $age = 25; } $object = new MyClass(); if (property_exists($object, 'age')) { echo "The 'age' property exists."; } else { echo "The 'age' property does not exist."; } // 输出:The 'age' property does not exist.
  1. 클래스 이름에 지정된 정적 속성이 있는지 확인하십시오.
 class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'name')) { echo "The 'name' static property exists."; } else { echo "The 'name' static property does not exist."; } // 输出:The 'name' static property exists.
  1. 클래스 이름에 지정된 정적 개인 속성이 있는지 확인하십시오.
 class MyClass { public static $name = "John"; private static $age = 25; } if (property_exists('MyClass', 'age')) { echo "The 'age' static property exists."; } else { echo "The 'age' static property does not exist."; } // 输出:The 'age' static property does not exist.
유사한 함수